/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.commons.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * 说明：
 * 日期格式化类
 * @Author：李智深
 * @Date：2012-03-14
 */
public class DateFormatUtil {
	
	public static final String FORMAT_STYLE_A = "yyyy-MM" ;
	public static final String FORMAT_STYLE_B = "MM-dd" ;
	public static final String FORMAT_STYLE_C = "HH:mm" ;
	public static final String FORMAT_STYLE_D = "MM-dd HH:mm" ;
	public static final String FORMAT_STYLE_E = "yyyy-MM-dd HH:mm" ;
	public static final String FORMAT_STYLE_F = "yyyy-MM-dd HH:mm:ss" ;
	public static final String FORMAT_STYLE_G = "yyyy-MM-dd" ;
	public static final String FORMAT_STYLE_I = "yyyyMMddHHmmss" ;
	public static final String FORMAT_STYLE_J = "yyyy/MM/dd HH:mm:ss" ;
	public static final String FORMAT_STYLE_K = "yyyy年MM月dd日" ;
	public static final String FORMAT_STYLE_L = "HH:mm:ss" ;

	/** 年-月 */
	public static String formatA(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_A) ;
		return sdf.format(date) ;
	}
	/** 月-日 */
	public static String formatB(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_B) ;
		return sdf.format(date) ;
	}
	/** 时-分 */
	public static String formatC(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_C) ;
		return sdf.format(date) ;
	}
	/** 月-日 时:分 */
	public static String formatD(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_D) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分 */
	public static String formatE(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_E) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分:秒 */
	public static String formatF(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_F) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分:秒 */
	public static String formatG(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_G) ;
		return sdf.format(date) ;
	}
	/** 年-月-日 时:分:秒 */
	public static String formatI(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_I) ;
		return sdf.format(date) ;
	}
	/** 年/月/日 时:分:秒 */
	public static String formatJ(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_J) ;
		return sdf.format(date) ;
	}

	/** 今天是2012年01月01日  星期五  时:分:秒 */
	public static String formatK(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_STYLE_K) ;
		StringBuffer sb=new StringBuffer();
		sb.append("今天是");
		sb.append(sdf.format(date)).append("    ");
		sb.append(getWeek(date)).append("    ");
		SimpleDateFormat sdfs = new SimpleDateFormat(FORMAT_STYLE_L) ;
		sb.append(sdfs.format(date));
		return sb.toString();
	}
	
	/**
	 * 获得上、下午
	 * @return
	 */
	public static String getAP_PM() {
		int am_pm = Calendar.getInstance().get(Calendar.AM_PM);
		switch (am_pm) {
		case 0:
			return "上午";
		case 1:
			return "下午";
		}
		return "获得AM_PM失败" ;
	}
	
	/**
	 * 获得当前日期的周几
	 * @return
	 */
	public static String getWeek() {
		return convertWeek(Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) ;
	}
	
	/**
	 * 获得指定日期的周几
	 * @param date java.util.Date日期对象
	 * @return
	 */
	public static String getWeek(Date date) {
		Calendar calendar = Calendar.getInstance(); 
		calendar.setTime(date) ;
		return convertWeek(Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1) ;
	}
	
	/**
	 * 获得指定日期的周几
	 * @param date 字符串
	 * @return
	 */
	public static String getWeek(String date) {
		Calendar calendar = Calendar.getInstance(); 
		try {
			calendar.setTime(new SimpleDateFormat(FORMAT_STYLE_G).parse(date)) ;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return convertWeek(calendar.get(Calendar.DAY_OF_WEEK) - 1) ;
	}

	/**
	 * 获得周几
	 * @return
	 */
	public static String convertWeek(int week) {
		
		switch (week) {
		case 0:
			return "星期日";
		case 1:
			return "星期一";
		case 2:
			return "星期二";
		case 3:
			return "星期三";
		case 4:
			return "星期四";
		case 5:
			return "星期五";
		case 6:
			return "星期六";
		}
		return "日前操作失败";
	}
	
	public static void main(String[] args) {
		System.out.println(DateFormatUtil.formatI(new Date()));
	}
	
}
